<template>
	<view class="page">
		<view class="head">
			<view class="item" :class="itemActive==4?'active':'ZW'" @click="itemBtn(4)">全部</view>
			<view class="item" :class="itemActive==0?'active':'ZW'" @click="itemBtn(0)">待付款</view>
			<view class="item" :class="itemActive==1?'active':'ZW'" @click="itemBtn(1)">进行中</view>
			<view class="item" :class="itemActive==2?'active':'ZW'" @click="itemBtn(2)">已完成</view>
		</view>
		<view class="content">
			<!-- 全部 -->
			<view class="item" v-if="itemActive==4?true:false">
				<view class="order_hint" v-if="ifShow">
					<image src="/static/images/order_hint.png"></image>
					<view>您还没有相关的订单</view>
				</view>
				<view class="it" v-for="(item, index) in orderList" :key="index">
					<view class="it_head">
						<view class="left">
							订单编号: <text style="margin-left: 15upx;">{{item.ordersn}}</text>
						</view>
						<view class="right">
							共{{item.service.length}}双鞋子
						</view>
					</view>
					<view class="it_content">
						<swiper class="swiper" :indicator-dots="item.service.length > 1 ? true : false" duration="500">
							<swiper-item v-for="(it, ind) in item.service" :key="ind">
								<view class="info">
									<view class="left">
										{{ind + 1}}、<text class="standard">{{it.standard_service_title}}</text><text>{{it.additional_title}}</text>
									</view>
									<view class="price">￥{{it.price}}</view>
								</view>
								<view class="status">
									<view class="arrows_1">--></view>
									<view class="arrows_2">--></view>
									<view class="arrows_3">--></view>
									<view class="status_it" v-for="(it2, ind2) in it.status" :key="ind2">
										<view class="iconBox">
											<uni-icon :type="it2.type" size="30" :color="it2.color"></uni-icon>
										</view>
										<view class="text" :style="{'color': it2.color}">{{it2.text}}</view>
									</view>
									<view class="shoes_number" :class="item.service.length > 1 ? 'ZW' : 'shoes_bottom'">鞋子编号: {{it.number == '' ? '暂未备注' : it.number}}</view>
								</view>
							</swiper-item>
						</swiper>
						<view class="foot">
							<view class="price">实付￥{{item.payable_price}}</view>
							<view class="btnBox">
								<view class="btn" v-if="item.status == 0 ? true : false" @click="opencloseOrder(item.id)">取消订单</view>
								<view class="btn" v-if="item.status == 0 ? true : false" @click="openorderDetail(item.id)">立即支付</view>
								<view class="btn" v-if="item.status == 1 ? true : false">已付款</view>
								<view class="btn" v-if="item.status == 2 ? true : false">已完成</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 待付款 -->
			<view class="item" v-if="itemActive==0?true:false">
				<view class="order_hint" v-if="ifShow">
					<image src="/static/images/order_hint.png"></image>
					<view>您还没有相关的订单</view>
				</view>
				<view class="it" v-for="(item, index) in orderList" :key="index">
					<view class="it_head">
						<view class="left">
							订单编号: <text style="margin-left: 15upx;">{{item.ordersn}}</text>
						</view>
						<view class="right">
							共{{item.service.length}}双鞋子
						</view>
					</view>
					<view class="it_content">
						<swiper class="swiper" :indicator-dots="item.service.length > 1 ? true : false" duration="500">
							<swiper-item v-for="(it, ind) in item.service" :key="ind">
								<view class="info">
									<view class="left">
										{{ind + 1}}、<text class="standard">{{it.standard_service_title}}</text><text>{{it.additional_title}}</text>
									</view>
									<view class="price">￥{{it.price}}</view>
								</view>
								<view class="status">
									<view class="arrows_1">--></view>
									<view class="arrows_2">--></view>
									<view class="arrows_3">--></view>
									<view class="status_it" v-for="(it2, ind2) in it.status" :key="ind2">
										<view class="iconBox">
											<uni-icon :type="it2.type" size="30" :color="it2.color"></uni-icon>
										</view>
										<view class="text" :style="{'color': it2.color}">{{it2.text}}</view>
									</view>
									<view class="shoes_number" :class="item.service.length > 1 ? 'ZW' : 'shoes_bottom'">鞋子编号: {{it.number == '' ? '暂未备注' : it.number}}</view>
								</view>
							</swiper-item>
						</swiper>
						<view class="foot">
							<view class="price">实付￥{{item.payable_price}}</view>
							<view class="btnBox">
								<view class="btn" @click="opencloseOrder(item.id)">取消订单</view>
								<view class="btn" @click="openorderDetail(item.id)">立即支付</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 已付款 -->
			<view class="item" v-if="itemActive==1?true:false">
				<view class="order_hint" v-if="ifShow">
					<image src="/static/images/order_hint.png"></image>
					<view>您还没有相关的订单</view>
				</view>
				<view class="it" v-for="(item, index) in orderList" :key="index">
					<view class="it_head">
						<view class="left">
							订单编号: <text style="margin-left: 15upx;">{{item.ordersn}}</text>
						</view>
						<view class="right">
							共{{item.service.length}}双鞋子
						</view>
					</view>
					<view class="it_content">
						<swiper class="swiper" :indicator-dots="item.service.length > 1 ? true : false" duration="500">
							<swiper-item v-for="(it, ind) in item.service" :key="ind">
								<view class="info">
									<view class="left">
										{{ind + 1}}、<text class="standard">{{it.standard_service_title}}</text><text>{{it.additional_title}}</text>
									</view>
									<view class="price">￥{{it.price}}</view>
								</view>
								<view class="status">
									<view class="arrows_1">--></view>
									<view class="arrows_2">--></view>
									<view class="arrows_3">--></view>
									<view class="status_it" v-for="(it2, ind2) in it.status" :key="ind2">
										<view class="iconBox">
											<uni-icon :type="it2.type" size="30" :color="it2.color"></uni-icon>
										</view>
										<view class="text" :style="{'color': it2.color}">{{it2.text}}</view>
									</view>
									<view class="shoes_number" :class="item.service.length > 1 ? 'ZW' : 'shoes_bottom'">鞋子编号: {{it.number == '' ? '暂未备注' : it.number}}</view>
								</view>
							</swiper-item>
						</swiper>
						<view class="foot">
							<view class="price">实付￥{{item.payable_price}}</view>
							<view class="btnBox">
								<view class="btn">已付款</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 已完成 -->
			<view class="item" v-if="itemActive==2?true:false">
				<view class="order_hint" v-if="ifShow">
					<image src="/static/images/order_hint.png"></image>
					<view>您还没有相关的订单</view>
				</view>
				<view class="it" v-for="(item, index) in orderList" :key="index">
					<view class="it_head">
						<view class="left">
							订单编号: <text style="margin-left: 15upx;">{{item.ordersn}}</text>
						</view>
						<view class="right">
							共{{item.service.length}}双鞋子
						</view>
					</view>
					<view class="it_content">
						<swiper class="swiper" :indicator-dots="item.service.length > 1 ? true : false" duration="500">
							<swiper-item v-for="(it, ind) in item.service" :key="ind">
								<view class="info">
									<view class="left">
										{{ind + 1}}、<text class="standard">{{it.standard_service_title}}</text><text>{{it.additional_title}}</text>
									</view>
									<view class="price">￥{{it.price}}</view>
								</view>
								<view class="status">
									<view class="arrows_1">--></view>
									<view class="arrows_2">--></view>
									<view class="arrows_3">--></view>
									<view class="status_it" v-for="(it2, ind2) in it.status" :key="ind2">
										<view class="iconBox">
											<uni-icon :type="it2.type" size="30" :color="it2.color"></uni-icon>
										</view>
										<view class="text" :style="{'color': it2.color}">{{it2.text}}</view>
									</view>
									<view class="shoes_number" :class="item.service.length > 1 ? 'ZW' : 'shoes_bottom'">鞋子编号: {{it.number == '' ? '暂未备注' : it.number}}</view>
								</view>
							</swiper-item>
						</swiper>
						<view class="foot">
							<view class="price">实付￥{{item.payable_price}}</view>
							<view class="btnBox">
								<view class="btn">已完成</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uniIcon from "@/components/uni-icon/uni-icon.vue";
	import { HTTP } from '@/pages/http.js';
	let http = new HTTP();
	export default {
		data(){
			return {
				ifShow: false,
				itemActive: 4,
				orderList: [],
				statusList: [
					{
						type: 'todo-list-o',
						color: '#ccc',
						text: '待处理'
					},
					{
						type: 'tosend',
						color: '#ccc',
						text: '清洗中'
					},
					{
						type: 'shop-collect-o',
						color: '#ccc',
						text: '待提货'
					},
					{
						type: 'certificate',
						color: '#ccc',
						text: '已完成'
					}
				]
			}
		},
		onLoad(e) {
			this.itemActive = e.num;
			this.orderInfoList(this.itemActive);
		},
		onShow() {
		},
		components: {
			uniIcon
		},
		methods:{
			//右上角分享功能
			onShareAppMessage: function (res) {
			  return {
			    title: 'unclearcare 球鞋洗护',
			    path: '/pages/index/index',
			    success: function (res) {
				  // 转发成功
			    },
			    fail: function (res) {
				  // 转发失败
			    }
			  }
			},
			itemBtn(num){
				this.itemActive = num;
				this.orderInfoList(this.itemActive)
			},
			orderInfoList(num){//获取订单列表
				uni.showLoading({
					title: '加载中..'
				})
				http.request({
					url: 'order/list',
					data: {
						page: 1,
						limit: 100,
						status: num == 4 ? num = '' : num = num
					},
					success:(res)=>{
						uni.hideLoading();
						if(res.data.code == 200){
							this.orderList = res.data.data;
							if(res.data.count != 0){
								this.ifShow = false;
								this.orderList.forEach((value, index)=>{
									value.service.forEach((val, ind)=>{
										var statusArr = JSON.parse(JSON.stringify(this.statusList));
										//判断邮寄还是到店改变状态
										if(value.type == 1){//店内
											statusArr[2].text = '待提货'
										}else{
											statusArr[2].text = '已发货'
										}
										statusArr.forEach((val2, ind2)=>{
											if(ind2 <= val.status){
												statusArr[ind2].color = '#3e3737';
											}
										});
										val.status = statusArr;
									})
									
								})
							}else{
								this.ifShow = true;
							}
						}
					},
					error:(err)=>{
						console.log('加载2');
					}
				})
			},
			openorderDetail(id){//立即支付
				uni.navigateTo({
					url: '/pages/index/placeOrder/orderDetail/index?id=' + id
				})
			},
			opencloseOrder(id){//取消订单
				var that = this;
				uni.showModal({
					title: '提示',
					content: '您确定要取消当前订单吗?',
					success: function (res) {
						if (res.confirm) {
							http.request({
								method: 'POST',
								url: 'order/cancel',
								data: {
									id
								},
								success:(res)=>{
									if(res.data.code = 200){
										uni.showToast({
											title: res.data.msg
										});
										that.orderInfoList(that.itemActive)
									}
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.page{
		height: 100%;
		background-color: #f5f5f9;
	}
	.head{
		display: flex;
		width: 100%;
		background-color: #fff;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		.item{
			width: 33.3%;
			line-height: 76upx;
			text-align: center;
			font-size: 28upx;
			color: #adadbb;
		}
		.item.active{
			font-weight: bold;
			color: #000;
		}
		.item.active::after{
			content: '';
			display: block;
			height: 4upx;
			width: 40upx;
			margin: 0 auto;
			margin-top: -4upx;
			background-color: #000;
		}
	}
	.content{
		background-color: #f5f5f9;
		height: 100%;
		padding-top: 100upx;
		.item{
			position: relative;
			background-color: #f5f5f9;
			min-height: 100%;
			.order_hint{
				position: absolute;
				top: 40%;
				left: 50%;
				transform: translate(-50%,-50%);
				image{
					width: 400upx;
					height: 400upx;
				}
				view{
					text-align: center;
					font-size: 30upx;
					margin-top: -50upx;
				}
			}
			.it{
				background-color: #fff;
				padding: 0 30upx;
				font-size: 24upx;
				margin-bottom: 20upx;
				.it_head{
					display: flex;
					height: 80upx;
					line-height: 80upx;
					justify-content: space-between;
					border-bottom: 1upx solid #eee;
					font-size: 28upx;
					.left{
						font-style: italic;
					}
				}
				.it_content{
					swiper{
						height: 270upx;
						.info{
							display: flex;
							justify-content: space-between;
							height: 80upx;
							line-height: 80upx;
							font-size: 26upx;
							.left{
								width: 560upx;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
								.standard{
									margin-right: 15upx;
								}
							}
						}
						.status{
							position: relative;
							display: flex;
							padding-bottom: 83upx;
							border-bottom: 1upx solid #eee;
							.arrows_1{
								position: absolute;
								top: 35upx;
								left: 150upx;
								font-size: 28upx;
								color: #c1c1c1;
							}
							.arrows_2{
								position: absolute;
								top: 35upx;
								left: 325upx;
								font-size: 28upx;
								color: #c1c1c1;
							}
							.arrows_3{
								position: absolute;
								top: 35upx;
								left: 500upx;
								font-size: 28upx;
								color: #c1c1c1;
							}
							.status_it{
								width: 25%;
								.iconBox{
									text-align: center;
								}
								.text{
									text-align: center;
								}
							}
							.shoes_number{
								position: absolute;
								bottom: 38upx;
								right: 0;
								// transform: translateX(-50%);
								color: #c1c1c1;
								font-style: italic;
								font-weight: 200;
							}
							.shoes_bottom{
								bottom: 20upx;
							}
						}
					}
					.foot{
						display: flex;
						height: 100upx;
						line-height: 100upx;
						justify-content: space-between;
						.price{
							font-size: 32upx;
							font-weight: bold;
						}
						.btnBox{
							display: flex;
							.btn{
								margin-top: 20upx;
								width: 140upx;
								height: 60upx;
								line-height: 58upx;
								border: 1upx solid #000;
								text-align: center;
								font-size: 26upx;
								margin-left: 10upx;
							}
						}
					}
				}
			}
			
		}
	}
</style>
